package com.jz.yanshe.ui;

import android.os.Bundle;
import android.widget.Toast;

import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import butterknife.OnClick;
import com.jz.yanshe.base.BaseActivity;
import com.jz.yanshe.base.BaseApplication;
import com.jz.yanshe.R;

/**
 * Created by Administrator on 2018/3/23.
 */

public class WXLoginActivity extends BaseActivity {




    @Override
    protected void initViews() {
        System.out.println(getAppInfo() +"   ...............");
    }

    @Override
    protected void initData() {
       BaseApplication.api = WXAPIFactory.createWXAPI(this,BaseApplication.APP_ID_WX,true);
        BaseApplication.api.registerApp(BaseApplication.APP_ID_WX);
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_wxlogin;
    }

    @OnClick(R.id.btn_wx_login)
    void btn_wx_login(){
        if (!BaseApplication.api.isWXAppInstalled()) {
            Toast.makeText(this,"您还未安装微信客户端",Toast.LENGTH_SHORT).show();
//            UIUtils.showToast("您还未安装微信客户端");
            return;
        }
        SendAuth.Req req = new SendAuth.Req();
        req.scope = "snsapi_userinfo";
        req.state = "wechat_sdk_demo_test";
        BaseApplication.api.sendReq(req);
        finish();
    }

    @OnClick(R.id.btn_phone_login)
    void btn_phone_login(){
        Bundle bundle = new Bundle();
        bundle.putString("type","phone");
        startActivity(LoginActivity.class,bundle);
        finish();
    }


    private String getAppInfo() {
        try {
            String pkName = this.getPackageName();
            String versionName = this.getPackageManager().getPackageInfo(
                    pkName, 0).versionName;
            int versionCode = this.getPackageManager()
                    .getPackageInfo(pkName, 0).versionCode;
            return pkName ;
        } catch (Exception e) {
        }
        return null;
    }

}
